package 因子分解和枚举.n的第k个因子;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

/**
 * TODO
 *
 * @className: nddkgyz2
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-05-07 00:24
 **/
public class nddkgyz2 {
    /**
     * 第二种解法
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(kthFactor(12, 3));
        System.out.println(kthFactor(7, 2));
        System.out.println(kthFactor(4, 4));
    }
    public static int kthFactor(int n, int k) {
        for (int i = 1; i <= n; ++i) {
            if (n % i == 0){
                --k;
                if (k == 0){
                    return i;
                }
            }
        }
        return -1;
    }
}
